package com.hualan.sfzy.service.course.serviceimpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hualan.sfzy.entity.course.Course;
import com.hualan.sfzy.mapper.course.CourseMapper;
import com.hualan.sfzy.service.course.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CourseServiceImpl implements CourseService {
    @Autowired
    private CourseMapper courseMapper;
    @Override
    public int add(Course course) {
        return courseMapper.insert(course);
    }

    @Override
    public int remove(Integer id) {
        return courseMapper.delete(id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return courseMapper.deleteBatch(ids);
    }

    @Override
    public int update(Course course) {
        return courseMapper.update(course);
    }

    @Override
    public Course findById(Integer id) {
        return courseMapper.selectById(id);
    }

    @Override
    public List<Course> find() {
        return courseMapper.select(null);
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, Course course) {
        PageHelper.startPage(pageNum, pageSize);
        List<Course> courses = courseMapper.select(course);
        PageInfo<Course> pageInfo = new PageInfo<>(courses);
        Map<String, Object> map = new HashMap<>();
        map.put("total", pageInfo.getTotal());
        map.put("pages", pageInfo.getPages());
        map.put("list", pageInfo.getList());
        return map;
    }
}

